package com.tuanzi.loan.web.bean.statistics;

import com.base.common.log.LogService;
import com.tuanzi.loan.business.service.statistics.BigClueStatChannelService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.request.statistics.BigClueStatChannelsearchRequest;
import com.tuanzi.loan.vo.response.statistics.BigClueStatChannelsearchResponse;
import com.tuanzi.loan.web.configuration.JSFListingBean;
import com.tuanzi.loan.web.lazy.statistics.StatBigClueChannelLazyDataModel;
import com.tuanzi.server.loan_base.util.DateUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class StatBigClueChannelBean extends JSFListingBean<BigClueStatChannelsearchRequest,BigClueStatChannelsearchResponse> {
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    @Autowired
    private BigClueStatChannelService service;
    @PostConstruct
    private void init() {
        initLazyDataModel();
    }

    private void initLazyDataModel() {
        $ = new BigClueStatChannelsearchRequest();
        try {
            $.setStartdate(sdf.parse(DateUtils.getDateBeforeDays(1)));
            $.setEnddate(sdf.parse(DateUtils.getCurrentDate()));
        } catch (ParseException e) {
            LogService.error("日期类型转换异常",e);
        }
        $.setCfrom_channel("-1000");
        lazyDataModel = new StatBigClueChannelLazyDataModel($);
    }

    public Set<String> getCfrom(){
        Set<String> set = new HashSet<>();
        List<String> list = service.returnCfrom();
        for (int i = 0; i <list.size() ; i++) {
            if ("null".equals(list.get(i))||list.get(i)==null||"".equals(list.get(i))){
                list.set(i,"菠萝贷站内");
            }
        }
        set.addAll(list);
        return set;
    }

    public String translateOwnner(String own){
        if ("1".equals(own.trim())||"".equals(own.trim())||"null".equals(own.trim())){
            return "粤好";
        }else if ("全部".equals(own.trim())){
            return "全部";
        }else{
            return "未知甲方";
        }
    }
}
